Skip to content

test: cover deposit ledger-error mapper arms#157

Draft
mbjorkqvist wants to merge 3 commits into
mainfrom
test/deposit-ledger-error-mappers
Draft

test: cover deposit ledger-error mapper arms#157
mbjorkqvist wants to merge 3 commits into
mainfrom
test/deposit-ledger-error-mappers

Conversation

@mbjorkqvist

Copy link
Copy Markdown
Contributor

Closes a test gap surfaced during the repo review: of the nine TransferFromError variants the deposit path translates in to_ledger_error, only TemporarilyUnavailable was exercised.

Adds unit tests that drive each variant through deposit() and assert the mapping:

  • InsufficientFunds / InsufficientAllowance carry their payload into the typed DepositError.
  • The variants a well-behaved ledger should never return (BadFee, BadBurn, CreatedInFuture, Duplicate, GenericError, TooOld) collapse to InternalError carrying the ledger's Display message — and notably do not trap.

Test-only; no production code changed.

Adds unit tests driving each TransferFromError variant through deposit():
the two payload-carrying arms (InsufficientFunds, InsufficientAllowance)
map to their typed DepositError counterparts, and the variants a
well-behaved ledger should never return collapse to InternalError carrying
the ledger's Display message rather than trapping.

Previously only TemporarilyUnavailable was exercised.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 18, 2026 09:27
Copilot AI previously approved these changes Jun 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Ready to approve

The change is test-only and correctly exercises each mapper arm with assertions aligned to the production to_ledger_error implementation.

Note: this review does not count toward required approvals for merging.

Pull request overview

Adds missing unit test coverage for deposit()’s TransferFromError -> DepositError mapping, ensuring all to_ledger_error match arms are exercised and that “unexpected” ledger errors are surfaced as InternalError strings rather than trapping.

Changes:

  • Add deposit() tests for InsufficientFunds and InsufficientAllowance mapping (including payload preservation).
  • Add a table-driven test covering “unexpected” TransferFromError variants mapping to LedgerTransferFromError::InternalError(format!("{e}")).
File summaries
File Description
canister/src/tests.rs Adds unit tests to cover all TransferFromError variants mapped by the deposit error mapper.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

canbench 🏋 (dir: canister) f308c52 2026-06-18 09:58:17 UTC

canister/canbench_results.yml is up to date
📦 canbench_results_benchmark.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 12 | regressed 0 | improved 0 | new 0 | unchanged 12]
    change:   [max +1.41M | p75 +1.17M | median +153.35K | p25 0 | min 0]
    change %: [max +1.51% | p75 +0.71% | median +0.14% | p25 0.00% | min 0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 12 | regressed 0 | improved 0 | new 0 | unchanged 12]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 12 | regressed 0 | improved 0 | new 0 | unchanged 12]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------

Only significant changes:
| status | name                                                          | calls |     ins |  ins Δ% | HI |  HI Δ% | SMI |  SMI Δ% |
|--------|---------------------------------------------------------------|-------|---------|---------|----|--------|-----|---------|
|   +    | bench_upgrade_1000_no_fills::pre_upgrade::save_snapshot       |     1 |   1.12M |  +3.43% |  0 |  0.00% | 128 |   0.00% |
|   +    | bench_upgrade_1000_no_fills::pre_upgrade                      |     1 |   1.20M |  +3.19% |  0 |  0.00% | 128 |   0.00% |
|   +    | bench_upgrade_full_depth::pre_upgrade::save_snapshot          |     1 |  11.87M |  +2.20% |  0 |  0.00% | 128 |   0.00% |
|   +    | bench_write_events::Matching                                  |     1 | 621.94K |  +2.16% |  1 |  0.00% |   0 |   0.00% |
|   +    | bench_write_events::CancelLimitOrder                          |     1 |   6.58K |  +2.14% |  0 |  0.00% |   0 |   0.00% |
|   -    | bench_upgrade_full_depth::post_upgrade::load_stable_memory    |     1 |   6.10K |  -4.75% |  0 |  0.00% |   0 |   0.00% |
|   -    | bench_upgrade_1000_no_fills::post_upgrade::load_stable_memory |     1 |   6.00K |  -4.82% |  0 |  0.00% |   0 |   0.00% |
|  new   | bench_read_events::SetHalt                                    |     1 |  47.30K |         |  0 |        |   0 |         |
|  new   | bench_write_events::SetHalt                                   |     1 |  69.75K |         |  0 |        |   0 |         |

ins = instructions, HI = heap_increase, SMI = stable_memory_increase, Δ% = percent change

---------------------------------------------------
CSV results saved to canbench_results.csv

mbjorkqvist and others added 2 commits June 18, 2026 09:44
…iven test

Match the codebase convention for error-path coverage (e.g.
should_reject_invalid_orders_without_modifying_book): a single test with a
(ledger reply, expected DepositError) cases table and one setup, rather than
the previous mix of per-variant tests plus a loop. Also covers
TemporarilyUnavailable so the table documents the full mapping.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 18, 2026 09:51
Copilot AI dismissed their stale review, a newer Copilot review was requested. June 18, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Ready to approve

The change is isolated to tests and correctly exercises the full error-mapping surface described in the PR without altering production code paths.

Note: this review does not count toward required approvals for merging.

Copilot's findings
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants